Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source map generation to bin/jsx #833

Closed
wants to merge 1 commit into from

Conversation

andrewdavey
Copy link
Contributor

Work in progress for #766

Assuming a directory contains foo.jsx, running jsx -x jsx --source-map . . will generate foo.js and foo.js.map.

The generated foo.js has the //# sourceMappingURL=foo.js.map comment appended.

Current limitations:

  • Nasty hack to commoner required to get the output directory.

@ghost ghost assigned benjamn Jan 7, 2014
@zpao
Copy link
Member

zpao commented Jan 7, 2014

I bet @benjamn can add something to commoner to make this easier so you don't have to hack it.

@benjamn
Copy link
Contributor

benjamn commented Jan 7, 2014

Have an issue filed to support this better: https://github.com/benjamn/commoner/issues/49

);
var code = transformed.code;
if (this.options.sourceMap) {
var mapFilename = writeSourceMap(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted on twitter, this is unsafe because the .process callback is only called the first time a module is built, so source map files will be written correctly for clean builds but not for incremental rebuilds.

Commoner needs to know about additional files before any processing takes place, so that it can make sure they get into the output directory, whether or not processing was necessary.

@benjamn
Copy link
Contributor

benjamn commented Jan 7, 2014

To be clear, I'd like to hold off on merging this pull request until Commoner has better support for writing multiple files per source module.

I would be willing to accept a version of this pull request that only appended the encoded source map to the end of the module (without writing a separate file), however.

@zpao
Copy link
Member

zpao commented Jan 7, 2014

I think starting with embedded sourcemaps is a good idea. Any idea how something like browserify handles them? (interested for our own purposes...)

@benjamn
Copy link
Contributor

benjamn commented Jan 7, 2014

Well, browserify can presumably write one source map for the entire bundle, which is somewhat easier than writing individual source maps for each module. It also has an option for embedding the map in the bundle file.

@zpao
Copy link
Member

zpao commented Jan 7, 2014

I was wondering what if you knew what it would do if each of the files it was putting into the bundle had an embedded map. No worries if you don't know!

@benjamn
Copy link
Contributor

benjamn commented Jan 7, 2014

Ah, I see. That definitely is relevant to our interests…

@andrewdavey
Copy link
Contributor Author

It seems that Browserify has good source map support: http://thlorenz.com/blog/browserify-sourcemaps It will extract source maps from source files and combine into a single source map for the bundle.

I'm happy to switch to only generating embedded source maps at the moment. Then once Commoner has been enhanced, we could add a way to toggle between embedded and external file. e.g. jsx --source-map <mode> ...

@ghost ghost assigned zpao Jan 8, 2014
@andrewdavey
Copy link
Contributor Author

The above commit generates inline source maps instead of files. So it should work well with Browserify.

benjamn added a commit to benjamn/react that referenced this pull request Jan 23, 2014
See [Commoner's README.md](
https://github.com/benjamn/commoner#generating-multiple-files-from-one-source-module)
for further explanation of the new functionality.

Among other potential benefits, this upgrade allows us to generate source
maps as standalone files rather than appending them inline to every
compiled module file under `build/modules/` (see facebook#833).
New `bin/jsx` options:

```
--source-map-inline
```

Generates inline source maps, useful for working with browserify.

```
--source-map-files
```

Generates a `.js.map` file for each generated `.js` file.
@andrewdavey
Copy link
Contributor Author

I've updated this now that Commoner supports multiple file generation (thanks to @benjamn ).

New command line options for bin/jsx : --source-map-inline and --source-map-files

@benjamn
Copy link
Contributor

benjamn commented Feb 3, 2014

Ping. Also, do we want to support --source-map-inline if --source-map-files is available? Can Browserify understand/combine non-inline source map files?

@benjamn
Copy link
Contributor

benjamn commented Feb 3, 2014

We probably want the same logic for bin/jsx-internal, too.

@andrewdavey
Copy link
Contributor Author

I think browserify only works with inline source maps.

@zpao
Copy link
Member

zpao commented Apr 2, 2014

What's happening here? I would love source maps, especially since we're doing it in the browser transform.

@zpao
Copy link
Member

zpao commented May 5, 2014

bueller

@andrewdavey
Copy link
Contributor Author

I'm not clear on what bin/jsx-internal is and where it's used. I assume I can add the same source options I added to bin/jsx.

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@zpao
Copy link
Member

zpao commented May 20, 2014

I actually would say that you can ignore bin/jsx-internal - that's just used for our internal module building. I don't really care about sourcemaps for those and if we need them later, we can revisit that.

@zpao
Copy link
Member

zpao commented Jun 16, 2014

I bet you could reuse some of the code from #910 now that it's merged. We also have some similar inline sourcemap code in https://github.com/facebook/react/blob/master/vendor/browser-transforms.js as well. We could probably start to share a bit (not super high-pri for me, but good form anyway)

@zpao
Copy link
Member

zpao commented Jul 13, 2014

Hey @andrewdavey, I appreciate you taking a stab at this, but I'm going to close it out and bring in #1825 which gets us part of the way there. I would still love to see external soucemaps so if you get a chance to come back to this, let me know!

PS, the work you did here definitely made it easier for me to write mine, so I appreciate it :)

@zpao zpao closed this Jul 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants